/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.semester.code.gui;

import aptech.semester.code.data.BankList;
import aptech.semester.code.entity.BankEntity;
import java.awt.print.PrinterException;
import java.text.MessageFormat;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author vi
 */
public class Bank extends javax.swing.JInternalFrame {


    private int Id;

    /**
     * Creates new form Position
     */
    public Bank(JFrame mainFrame) {
        initComponents();
        initControl();
        txtBankName.setEditable(false);
        txtBankAddress.setEditable(false);
        txtBankDescription.setEditable(false);
        btnSaveBank.setEnabled(false);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnBank = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbBank = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        btnAddBank = new javax.swing.JButton();
        btnUpdateBank = new javax.swing.JButton();
        btnDeleteBank = new javax.swing.JButton();
        btnExitBank = new javax.swing.JButton();
        btnSaveBank = new javax.swing.JButton();
        btnExportBank = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtBankAddress = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtBankDescription = new javax.swing.JTextArea();
        txtBankName = new javax.swing.JTextField();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        pnBank1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbBank1 = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        btnAdd1 = new javax.swing.JButton();
        btnUpdate1 = new javax.swing.JButton();
        btnDelete1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();

        setClosable(true);
        setTitle("Bank");
        setMaximumSize(new java.awt.Dimension(800, 950));
        setMinimumSize(new java.awt.Dimension(100, 100));
        setPreferredSize(new java.awt.Dimension(800, 600));

        pnBank.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "List Bank", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        tbBank.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "BANK_NAME", "ADDRESS", "DESCRIPTION"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbBank.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbBankMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(tbBank);

        javax.swing.GroupLayout pnBankLayout = new javax.swing.GroupLayout(pnBank);
        pnBank.setLayout(pnBankLayout);
        pnBankLayout.setHorizontalGroup(
            pnBankLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnBankLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 31, Short.MAX_VALUE))
        );
        pnBankLayout.setVerticalGroup(
            pnBankLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnBankLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Command", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        jPanel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        btnAddBank.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnAddBank.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/add.png"))); // NOI18N
        btnAddBank.setText("Add New");
        btnAddBank.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddBankActionPerformed(evt);
            }
        });

        btnUpdateBank.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnUpdateBank.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/edit.png"))); // NOI18N
        btnUpdateBank.setText("Update");
        btnUpdateBank.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateBankActionPerformed(evt);
            }
        });

        btnDeleteBank.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnDeleteBank.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/delete.png"))); // NOI18N
        btnDeleteBank.setText("Delete");
        btnDeleteBank.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteBankActionPerformed(evt);
            }
        });

        btnExitBank.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnExitBank.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/exit.png"))); // NOI18N
        btnExitBank.setText("Exit");
        btnExitBank.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitBankActionPerformed(evt);
            }
        });

        btnSaveBank.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnSaveBank.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/save.png"))); // NOI18N
        btnSaveBank.setText("Save");
        btnSaveBank.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveBankActionPerformed(evt);
            }
        });

        btnExportBank.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnExportBank.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/report.png"))); // NOI18N
        btnExportBank.setText("Export");
        btnExportBank.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportBankActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnAddBank)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                .addComponent(btnSaveBank)
                .addGap(41, 41, 41)
                .addComponent(btnUpdateBank)
                .addGap(39, 39, 39)
                .addComponent(btnDeleteBank)
                .addGap(35, 35, 35)
                .addComponent(btnExportBank)
                .addGap(29, 29, 29)
                .addComponent(btnExitBank)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDeleteBank)
                    .addComponent(btnUpdateBank)
                    .addComponent(btnAddBank)
                    .addComponent(btnSaveBank)
                    .addComponent(btnExitBank)
                    .addComponent(btnExportBank))
                .addGap(37, 37, 37))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel1.setText("Bank Name");

        jLabel2.setText("Address");

        jLabel3.setText("Description");

        txtBankDescription.setColumns(20);
        txtBankDescription.setRows(5);
        jScrollPane3.setViewportView(txtBankDescription);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(85, 85, 85)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtBankAddress)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                    .addComponent(txtBankName))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtBankName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtBankAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21))
        );

        jInternalFrame1.setClosable(true);
        jInternalFrame1.setTitle("Bank");
        jInternalFrame1.setMaximumSize(new java.awt.Dimension(750, 900));
        jInternalFrame1.setPreferredSize(new java.awt.Dimension(800, 600));

        pnBank1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "List Bank", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        tbBank1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"1", "ACB", "123 Ly Thuong Kiet,Quan 10,Tp.HCM", "No description"},
                {"2", "Dong A", "590 CMT8, Quan 3,Tp.HCM", "No description"},
                {"3", "Sacombank", "143 Nguyen Thai Hoc,Quan 1,Tp.HCM", "No description"},
                {"4", "VIB", "43 Dien Bien Phu,Quan 3,Tp.HCM", "No description"},
                {"5", "ACB", "69 Ben Nghe,Quan 1,Tp.HCM", "No description"},
                {"6", "Vietcombank", "70 Thanh Thai,Quan 5,Tp.HCM", "No description"},
                {"8", "Dong A", "43 Nguyen Tri Phuong,Quan 8,Tp.HCM", "No description"},
                {"9", "Sacombank", "234 Nguyen Dinh Chieu,Quan 3,Tp.HCM", "No description"},
                {"10", "ACB", "67 Phan Boi Chau,Quan 7,Tp.HCM", "No description"}
            },
            new String [] {
                "ID", "BANK_NAME", "ADDRESS", "DESCRIPTION"
            }
        ));
        jScrollPane2.setViewportView(tbBank1);

        javax.swing.GroupLayout pnBank1Layout = new javax.swing.GroupLayout(pnBank1);
        pnBank1.setLayout(pnBank1Layout);
        pnBank1Layout.setHorizontalGroup(
            pnBank1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
        );
        pnBank1Layout.setVerticalGroup(
            pnBank1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnBank1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Command", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        btnAdd1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnAdd1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/add.png"))); // NOI18N
        btnAdd1.setText("Add New");
        btnAdd1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdd1ActionPerformed(evt);
            }
        });

        btnUpdate1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnUpdate1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/edit.png"))); // NOI18N
        btnUpdate1.setText("Update");
        btnUpdate1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdate1ActionPerformed(evt);
            }
        });

        btnDelete1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnDelete1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/delete.png"))); // NOI18N
        btnDelete1.setText("Delete");

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/exit.png"))); // NOI18N
        jButton2.setText("Exit");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addComponent(btnAdd1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnUpdate1)
                .addGap(68, 68, 68)
                .addComponent(btnDelete1)
                .addGap(78, 78, 78)
                .addComponent(jButton2)
                .addGap(114, 114, 114))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(btnDelete1)
                    .addComponent(btnUpdate1)
                    .addComponent(btnAdd1))
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel4.setText("Bank Name");

        jLabel5.setText("Address");

        jLabel6.setText("Description");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(85, 85, 85)
                        .addComponent(jTextField6))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(85, 85, 85)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnBank1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addComponent(pnBank1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(pnBank, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 399, Short.MAX_VALUE)
                    .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 398, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnBank, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 287, Short.MAX_VALUE)
                    .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 287, Short.MAX_VALUE)))
        );

        try {
            jInternalFrame1.setMaximum(true);
        } catch (java.beans.PropertyVetoException e1) {
            e1.printStackTrace();
        }

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddBankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddBankActionPerformed
        txtBankName.setText("");
        txtBankAddress.setText("");
        txtBankDescription.setText("");
        txtBankName.setEditable(true);
        txtBankAddress.setEditable(true);
        txtBankDescription.setEditable(true);
        btnAddBank.setEnabled(false);
        btnUpdateBank.setEnabled(false);
        btnDeleteBank.setEnabled(false);
        btnSaveBank.setText("Save Add");
        btnSaveBank.setEnabled(true);
        tbBank.setEnabled(false);
        
     

    }//GEN-LAST:event_btnAddBankActionPerformed

    private void btnUpdateBankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateBankActionPerformed
        int r = tbBank.getSelectedRow();
        // Lay chi so dong dc chon

        if (r < 0) {
            JOptionPane.showMessageDialog(null, "Please choose the row to update!");
            return;
        } else {
            txtBankName.setEditable(true);
            txtBankAddress.setEditable(true);
            txtBankDescription.setEditable(true);
            btnAddBank.setEnabled(false);
            btnDeleteBank.setEnabled(false);
            btnSaveBank.setText("Save Update");
            btnSaveBank.setEnabled(true);
            btnUpdateBank.setEnabled(false);
            tbBank.setEnabled(false);
        }

    }//GEN-LAST:event_btnUpdateBankActionPerformed

    private void btnAdd1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdd1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnAdd1ActionPerformed

    private void btnUpdate1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdate1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnUpdate1ActionPerformed

    private void tbBankMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbBankMousePressed
        // lay chi so dong duoc chon tren jtable
        int i = tbBank.getSelectedRow();

        //lay du lieu cua cac cac o tren dong nay, fill vo cac control nhap lieu
        txtBankName.setText(tbBank.getValueAt(i, 1).toString());
        txtBankAddress.setText(tbBank.getValueAt(i, 2).toString());
        txtBankDescription.setText(tbBank.getValueAt(i, 3).toString());
    }//GEN-LAST:event_tbBankMousePressed

    private void btnSaveBankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveBankActionPerformed
        if (btnSaveBank.getText().equals("Save Add")) {
            String name = txtBankName.getText().trim();
            String address = txtBankAddress.getText().trim();
            String description = txtBankDescription.getText().trim();

            if (name.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Bank Name can not blank!");
                txtBankName.requestFocus();
                return;
            }
            if(txtBankName.getText().trim().matches("^[\\d]+$")){
                JOptionPane.showMessageDialog(null, "Bank name can not numberic");
                txtBankName.requestFocus();
                return;
            }
            if(name.length() > 50){
                JOptionPane.showMessageDialog(null, "Bank name less than 50 character");
                txtBankName.requestFocus();
                return;
            }
            
            if (address.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Bank address can not blank!");
                txtBankAddress.requestFocus();
                return;
            }
            if(address.length() > 1000){
                JOptionPane.showMessageDialog(null, "Bank address less than 1000 character!");
                txtBankAddress.requestFocus();
                return;
            }
             if(txtBankDescription.getText().trim().matches("^[\\d]+$")){
                JOptionPane.showMessageDialog(null, "Description can not numberic");
                txtBankDescription.requestFocus();
                return;
            }

            BankEntity b = new BankEntity();
            b.setBankName(txtBankName.getText().trim());
            b.setAddress(txtBankAddress.getText().trim()); 
            b.setDescription(txtBankDescription.getText().trim());

            BankList bl = new BankList();
            if (bl.insert(b) == true) {
                JOptionPane.showMessageDialog(null, "Insert successfull");
                modelBank = (DefaultTableModel) tbBank.getModel();
                modelBank.setRowCount(0);

                for (BankEntity item : new BankList().getAllBank()) {
                    modelBank.addRow(item.toVector());
                }
                btnSaveBank.setEnabled(false);
                btnAddBank.setEnabled(true);
                btnUpdateBank.setEnabled(true);
                btnDeleteBank.setEnabled(true);
                tbBank.setEnabled(true);
                txtBankName.setEditable(false);
                txtBankAddress.setEditable(false);
                txtBankDescription.setEditable(false);

            } else {
                JOptionPane.showMessageDialog(null, "Insert failed");
                return;
            }
        }

        if (btnSaveBank.getText().equals("Save Update")) {
            int row = tbBank.getSelectedRow();
            String a = tbBank.getValueAt(row, 0).toString();
            int ID = Integer.parseInt(a);
            
            BankEntity b = new BankEntity();
            b.setBankId(ID);
            b.setBankName(txtBankName.getText().trim());
            b.setAddress(txtBankAddress.getText().trim());
            b.setDescription(txtBankDescription.getText().trim());

            BankList bl = new BankList();
            if (bl.update(b) == true) {
                JOptionPane.showMessageDialog(null, "Update successfull");
                modelBank = (DefaultTableModel) tbBank.getModel();
                modelBank.setRowCount(0);
                for (BankEntity item : new BankList().getAllBank()) {
                    modelBank.addRow(item.toVector());
                    
                btnAddBank.setEnabled(true);
                btnUpdateBank.setEnabled(true);
                btnDeleteBank.setEnabled(true);
                tbBank.setEnabled(true);
                txtBankName.setEditable(false);
                txtBankAddress.setEditable(false);
                 txtBankDescription.setEditable(false);
                btnSaveBank.setEnabled(false);
                }

            } else {
                JOptionPane.showMessageDialog(null, "Update failed");
                return;
            }
        }
    }//GEN-LAST:event_btnSaveBankActionPerformed

    private void btnDeleteBankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteBankActionPerformed

        // lay chi so dong duoc chon tren jTable
        int i = tbBank.getSelectedRow();
        if (i < 0) {
            JOptionPane.showMessageDialog(null, "Please choose row to delete!");
        } else {
            int r = JOptionPane.showConfirmDialog(null, "Are you sure ?", "Notify", JOptionPane.YES_NO_OPTION);
            if (r == JOptionPane.OK_OPTION) {
                int id = Integer.parseInt(tbBank.getValueAt(i, 0).toString());
                if (new BankList().delete(id) == true) {
                    JOptionPane.showMessageDialog(null, "Delete successfull!");

                    modelBank = (DefaultTableModel) tbBank.getModel();
                    modelBank.setRowCount(0);
                    for (BankEntity item : new BankList().getAllBank()) {
                        modelBank.addRow(item.toVector());
                    }
                    return;
                } else {
                    JOptionPane.showMessageDialog(null, "Delete failed");
                    return;
                }

            }

        }

    }//GEN-LAST:event_btnDeleteBankActionPerformed

    private void btnExitBankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitBankActionPerformed
        System.exit(0);
    }//GEN-LAST:event_btnExitBankActionPerformed

    private void btnExportBankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportBankActionPerformed
       MessageFormat headerFormat= new MessageFormat("Bank Report");
            MessageFormat footerFormat = new  MessageFormat("Page {0}");
        try {
            tbBank.print(JTable.PrintMode.FIT_WIDTH,headerFormat, footerFormat);
        } catch (PrinterException ex) {
            Logger.getLogger(Bank.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnExportBankActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd1;
    private javax.swing.JButton btnAddBank;
    private javax.swing.JButton btnDelete1;
    private javax.swing.JButton btnDeleteBank;
    private javax.swing.JButton btnExitBank;
    private javax.swing.JButton btnExportBank;
    private javax.swing.JButton btnSaveBank;
    private javax.swing.JButton btnUpdate1;
    private javax.swing.JButton btnUpdateBank;
    private javax.swing.JButton jButton2;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JPanel pnBank;
    private javax.swing.JPanel pnBank1;
    private javax.swing.JTable tbBank;
    private javax.swing.JTable tbBank1;
    private javax.swing.JTextField txtBankAddress;
    private javax.swing.JTextArea txtBankDescription;
    private javax.swing.JTextField txtBankName;
    // End of variables declaration//GEN-END:variables

    DefaultTableModel modelBank;

    private void initControl() {
        modelBank = (DefaultTableModel) tbBank.getModel();

        //fill du lieu tu bang tbBank vo model
        BankList o = new BankList();
        for (BankEntity item : o.getAllBank()) {
            modelBank.addRow(item.toVector());
        }
    }

}
